<template>
  <div class="editType">
    <el-form
      ref="form"
      :model="form"
      label-width="80px"
    >
      <el-form-item label="类型编码">
        <el-input v-model="form.encode" :disabled="type=='edit'" />
      </el-form-item>
      <el-form-item label="类型名称">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="状  态">
        <el-radio-group v-model="form.enabledmark">
          <el-radio label="启用" />
          <el-radio label="停用" />
        </el-radio-group>
      </el-form-item>
    </el-form>
    <p style="text-align:right">
      <span
        class="greenBtn"
        @click="$emit('close')"
      >取消</span>
      <span
        class="greenBtn"
        @click="confirm"
      >确定</span>
    </p>
  </div>
</template>

<script>
export default {
  name: 'EditType',
  props: {
    type: {
      type: String,
      default: 'add'
    },
    info: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      form: {
        enabledmark: '启用',
        name: '',
        encode: ''
      }
    }
  },
  mounted() {
    if (this.type !== 'add') {
      this.form = JSON.parse(JSON.stringify(this.info))
      this.form.enabledmark = this.form.enabledmark === 1 ? '启用' : '停用'
    }
  },
  methods: {
    confirm() {
      const data = JSON.parse(JSON.stringify(this.info))
      data.name = this.form.name
      data.encode = this.form.encode
      data.enabledmark = this.form.enabledmark === '启用' ? 1 : 0
      this.$emit('close', data)
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
